
<?php
$id = $_GET['id'];
$shopcode = 'shop' . $id;
if (isset(Yii::app()->request->cookies[$shopcode]->value)) {
    $shoparry = Yii::app()->request->cookies[$shopcode]->value;
    $savedCardArray = json_decode($shoparry, true);
} else {
    $shoplist = Shop::model()->findAll(' `flag`=1 and `shopCode`="' . $id . '"');

    if (!empty($shoplist)) {
        foreach ($shoplist as $c) {
            $idshop = $c->id;
            $shopName = $c->shopName;
            $shopCode = $c->shopCode;
            $shopshop = array($idshop, $shopName, $shopCode, $c->logo, $c->url_logo, $c->footer, $c->address, $c->phone, $c->metakeyword, $c->metadisception, $c->yotube, $c->facebook, $c->google, $c->twitter);
        }


        if (!empty($shopshop)) {
            $json = json_encode($shopshop, true);

            $cookie = new CHttpCookie($shopcode, $json);

            $cookie->expire = time() + 60 * 60 * 24;
            Yii::app()->request->cookies[$shopcode] = $cookie;
        } else {
            $this->redirect('http://salesmartlink.com');
        }
    } else {
        $this->redirect('http://salesmartlink.com');
    }
}
$shoparry = Yii::app()->request->cookies[$shopcode]->value;
//$shopary = stripslashes($shoparry); dong nay bo dau tieng viet
$savedCardArray = json_decode($shoparry, true);
?>


<div class="bao" style="height: 393px">
    <div class="title_top_sup">Xem nhiều nhất</div>
    <ul id="mycarousel" class="jcarousel-skin-tango">
        <?php
        $urlbtnxem = 'http://www.salesmartlink.com/icon/btnxem.PNG';
        $criteria = new CDbCriteria();
        $criteria->condition = 'flag=1 and shopid='.$savedCardArray[0].' and `pr_enddate` > CURDATE() order by `position` ASC';
        $produc = ShopProduct::model()->findAll($criteria);
        if (!empty($produc)) {
            foreach ($produc as $pr) {
                ?>
                <li>

                    <div class="boxsp">
                        <div class="sale">
                            <div class="txtdiscount">
                                <?php echo $pr->discount; ?>
                                <span>%</span>
                            </div>
                        </div>
                        <div class="boxspImg">
                            <?php
                            $getUrl = $pr->pr_url;
                            $tang = "_top";
                            if ($getUrl === "") {
                                $getUrl = $this->createUrl('/shop/' . $savedCardArray[2] . '/noi-dung') . '/' . $pr->prid . '/' . $pr->asia_name . '/';
                            } else {
                                $tang = "_blank";
                            }
                            ?>
                            <a href="<?php echo $getUrl; ?>" title="<?php echo $pr->pr_name; ?>" target="<?php echo $tang; ?>">
                                <img src="<?php echo Yii::app()->request->baseUrl . '/uploadshop/product/' . $pr->avatar ?>" width="190" height="205">
                            </a>
                        </div>
                        <div class="boxspTitle">
                            <a href="<?php echo $getUrl; ?>" title="<?php echo $pr->pr_name; ?>" target="<?php echo $tang; ?>">
                                <?php echo $pr->pr_name; ?>
                            </a>
                        </div>
                        <div class="boxspPrice">
                            <div class="txttimer">
                                <div class="product-date-<?php echo $pr->prid; ?>"></div>

                                <script>
                                    jQuery(document).ready(function() {

                                        jQuery(".product-date-<?php echo $pr->prid; ?>").countdown({
        <?php
        if (($pr->pr_enddate) == '') {
            $date = "1/1/2013 0:0:0";
        } else {
            $date = $pr->pr_enddate;
        }
        ?>

                                            date: "<?php echo $date; ?>",
                                            render: function(data) {
                                                jQuery(this.el).html("Còn " + this.leadingZeros(data.days, 2) + " <span> ngày </span>");
                                            }
                                        });

                                    });

                                </script>
                            </div>
                            <div class="btnXem">

                                <a href="<?php echo $getUrl; ?>" title="<?php echo $pr->pr_name; ?> " target="<?php echo $tang; ?>"><img src="<?php echo $urlbtnxem; ?>"></a>
                            </div>
                        </div>
                    </div>

                </li>
                <?php
            }
        }
        ?>
    </ul>
    <div class="clear"></div>
</div>

